(function($) {
  //导航菜单
	$("#header .menu li").hover(function(){
		$(this).oneTime(50,function(){ 
			$(this).addClass("hover active");
	  });
		$(this).find('.sec-menu-list').height($(this).find('.sec-menu-list .sec-menu-w').height() + 25);
	},function(){
	  $(this).oneTime(50,function(){ 
		$(this).removeClass("hover active");
		$(this).find('.sec-menu-list').height(0);
	  });
	});

	$('.cate-list').on('mouseenter', function() {
		$(".nav_right").removeClass('hide');
	}).on('mouseleave', function() {
		$(".nav_right").addClass('hide');
		$(".sub").addClass('hide');
	}).on('mouseenter', 'li', function(e) {
		var li_data = $(this).attr('data-id');
		$(".sub").addClass('hide');
		$('.sub[data-id="' + li_data + '"]').removeClass('hide');
	})
})(jQuery);

function shopAjax (config) {
	this.options = {
		"method": 'POST',
		"data": '',
		"dataType": 'json',
	};
	$.extend(true, this.options, config);
	var options = this.options;
	$.ajax({
		type: options.method||'post',
		url: options.url,
		dataType: options.dataType||'json',
		data: options.data
	}).done(function (response) {
		if(response.status){
			options.callback(response);
			return true;
		}else{
			layer.msg(response.msg);
		}
	}).fail(function (XMLHttpRequest) {
		console.log(XMLHttpRequest);
		var errorText = '';
		switch (XMLHttpRequest.status) {

			case 422:
				var errors = XMLHttpRequest.responseJSON.errors;
				if(typeof errors == 'object') {
					for (var index in errors) {
						errorText = errors[index][0];
						layer.msg(XMLHttpRequest.responseJSON.msg,{icon: 5});
						break;
					}
				}else{
					errorText = XMLHttpRequest.responseJSON.msg;
				}
				break;
			case 500:
				errorText ='服务器内部错误';
				break;
			default:
				errorText ='网络错误,请稍后再试';
		}

		layer.msg(errorText,{icon: 5});
	}).always(function () {

	});
};

function str2arr(str,glue) {
	if (glue == undefined || glue == ''){
		glue=',';
	}
	if(typeof str !== "string"){
		return str;
	}
	return (str.split(glue)).filter(function (item) {
		return item;
	})
}

